import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.io.ClassPathResource;
import service.PersionService;

/**
 * Created by yan_li on 2017/9/19.
 */
public class SpringTest {

    /**
     * 正常使用的时候写法
     */
    public static void testGetBean() {
        ApplicationContext ac = new ClassPathXmlApplicationContext("beans.xml");
        PersionService persion = (PersionService) ac.getBean("persion");
        persion.say();
    }

    /**
     * spring 运行时执行的流程
     */
    public static void springRunList() {
        ClassPathResource resource = new ClassPathResource("beans.xml");
        DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
        XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(factory);
        int registerCount = reader.loadBeanDefinitions(resource);
        System.out.println(registerCount);
        PersionService persion = (PersionService) factory.getBean("persion");
        persion.say();
    }

    public static void main(String[] args) {
        testGetBean();
        springRunList();
    }

}
